package com.pk.platform.business.common.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.pk.platform.business.common.dao.IArrangeDao;
import com.pk.platform.business.common.service.IArrangeService;
import com.pk.platform.domain.common.Child;
import com.pk.platform.domain.common.ChildArrange;
import com.pk.platform.util.DateConverter;
import com.pk.platform.util.constant.Constant;

public class ArrangeServiceImpl implements IArrangeService {

	private IArrangeDao arrangeDao;
	
	public void addChildArrange(ChildArrange arrange) {
		arrangeDao.add(arrange);
		Child child = arrangeDao.get(Child.class, arrange.getChild().getId());
		arrangeDao.addOperateLog("新增学童日程安排", Constant.SUCCESSFUL, child.getKindergarten());
	}

	public void delChildArrange(String id) {
		ChildArrange arrange = this.queryChildArrangeById(id);
		arrangeDao.addOperateLog("删除学童日程安排", Constant.SUCCESSFUL, arrange.getChild().getKindergarten());
		arrangeDao.delete(ChildArrange.class, id);
	}

	public ChildArrange queryChildArrangeById(String id) {
		return arrangeDao.get(ChildArrange.class, id);
	}

	public List<Map<String, Object>> queryChildArrangeByTimeOfChild(String childId,
			Date start, Date end) {
		String sDate = DateConverter.dateToString(start, DateConverter.FORMAT_ONE);
		String eDate = DateConverter.dateToString(end, DateConverter.FORMAT_ONE);
		return arrangeDao.queryChildArrangeByTimeOfChild(childId, sDate, eDate);
	}

	public void updateChildArrange(ChildArrange arrange) {
		ChildArrange ca = this.queryChildArrangeById(arrange.getId());
		ca.setTitle(arrange.getTitle());
		ca.setDescription(arrange.getDescription());
		arrangeDao.addOperateLog("修改学童日程安排", Constant.SUCCESSFUL, ca.getChild().getKindergarten());
	}

	public IArrangeDao getArrangeDao() {
		return arrangeDao;
	}

	public void setArrangeDao(IArrangeDao arrangeDao) {
		this.arrangeDao = arrangeDao;
	}

}
